require.config({
    baseUrl: '../../',
    paths: {
        jquery: 'plugins/jQuery/jquery-2.2.3.min',
        flavr: 'plugins/flavr/flavr.min',
        select2: 'plugins/select2/select2.min',
        public: 'public/js/public.min'
    },
    shim: {
        flavr: {
            deps: ['jquery']
        },
        select2: {
            deps: ['jquery']
        }
    }
});
require(['jquery', 'flavr', 'select2', 'public'], function ($) {
    $(function(){
        var sxhxzb = {
            init: function () {
                this.load();
            },
            load: function () {
                var _this = this;
                $('#header').load('../head.html', function () {
                    _this.year = $('.header-select-year').on('change', function () {
                        _this.setTitle();
                        _this.queryData();
                    });
                    _this.month = $('.header-select-month').on('change', function () {
                        _this.setTitle();
                        _this.queryData();
                    });

                    _this.setTitle();
                    _this.queryData();
                });
                $('#navigator').load('../left-nav.html');
            },
            setTitle: function () {
                var year = this.year.find('option:selected').text();
                var month = this.month.find('option:selected').text();
                $('.title').html(year + '年' + month + '月' + GetQueryString('name') + '三项核心指标');
            },
            queryData: function () {
                publicAjax(basePath + 'queryThreeCore', 'post', {
                    typeId: GetQueryString('typeId'),
                    year: this.year.val(),
                    month: this.month.val()
                }, function (data) {
                    console.log(data);
                    if (data.ret === 1) {
                        var list = data.data || [],
                            str = '';
                        if (list.length) {
                            var year = '今';
                            for (var i = 0; i < list.length; i++) {
                                str += (
                                    '<tr>' +
                                    '<td>' + fixStr(list[i].hospitalName) + '</td>' +
                                    '<td class="text-right">' + fixLine2(list[i].medicalIncomeRate) + '</td>' +
                                    '<td class="text-right">' + fixLine2(list[i].medicineRate) + '</td>' +
                                    '<td class="text-right">' + fixLine2(list[i].hygienicMaterialRate) + '</td>' +
                                    '</tr>'
                                );
                                year = list[i].year || year;
                            }

                            // $('.table-year').html(year);
                        } else {
                            str = '<tr><td colspan="10" class="text-center">暂无数据!</td></tr>';
                        }
                        $('#table-data').find('tbody').html(str);
                    } else {
                        flavrShowByTime(data.msg, null, 'error', false);
                    }
                });
            }
        };

        sxhxzb.init();
    });
});